<?php

   class Company_User extends database_object{
        
        public $id;
        public $company_id;
        public $product_id;
        public $user_id;
        
        
        protected static $table_name = "bo_company_user";
        protected static $db_fields = array("id", "company_id", "product_id","user_id");
        
        
        //Checks wether the connection between user, company and product exists
          public  function exist($userid,$companyid,$productid){
            $database   = Database::getInstance();
            $userid     = $database->escape_value($userid);
            $companyid  = $database->escape_value($companyid);
            $productid  = $database->escape_value($productid);

            $sql  = "SELECT * FROM " . self::$table_name ;
            $sql .= " WHERE user_id = $userid ";
            $sql .= "AND company_id = $companyid ";
            $sql .= "AND product_id = $productid ";
            $sql .= "LIMIT 1";
            $result_array = self::find_by_sql($sql);
                        
            return !empty($result_array) ? array_shift($result_array) : false;
	}
        
        // Finds user by id from query
          public function findByUserid($userid){
       
                $sql            = "SELECT * FROM " . self::$table_name;
                $sql           .= " WHERE user_id=".$userid.";";
                $result_array   = self::find_by_sql($sql);
            
                return !empty($result_array) ? $result_array : false;
        }
        
     
     
   }
   $company_product  = new Company_User();
   
   ?>